<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="../bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="../Flat-UI-master/dist/js/vendor/jquery.min.js"></script>
    <script src="../bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="../Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <title></title>
    <style>
        .row{
            margin-left: 20px;
            margin-right: 20px;;
        }
        .line-center{
            line-height:50px;
            text-align: center;
        }
        .row input{
            width: 50px;
        }
        .list-group-item:hover{
            background: #27ae60;

        }
        .list-group-item div:first-child:hover{

            cursor: pointer;
        }
        th{
            text-align: right;
            width: 200px;;
        }
        td{
            text-align: left;
            padding: 10px;
        }
        .table th{
            text-align: center;
        }
        .table td{
            text-align: center;
        }
    </style>
    <script>
        function myClick(n){
            location.href = "OrderInfo.html";
        }
        function btnClick(){
            alert("btn");
            return false;
        }
        $(function(){

        })
    </script>
    <script src="../js/jquery-3.2.1.min.js"></script>
</head>
<body>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">图书商城</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="Index.html">首页</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
                <li></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm" id="login">
                <!--<li><a href="Login.html">登录</a></li>-->
                <!--<li><a href="Register.html">注册</a></li>-->
                <li><a id="out">退出</a></li>
                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>
<!--content-->
<div class="container">
    <div class="row thumbnail center col-sm-12">
        <div class="col-sm-12">
            <h1 class="text-center" style="margin-bottom: 30px">订单详情</h1>
        </div>

        <div class="col-sm-12 ">
           <table>
               <tr>
                   <th>订单编号：</th><td id="oid"></td>
               </tr>
               <tr>
                   <th>订单状态：</th><td id="state"></td>
               </tr>
               <tr>
                   <th>收货人姓名：</th><td id="username"></td>
               </tr>
               <tr>
                   <th>收货人地址：</th><td id="address"></td>
               </tr>
               <tr>
                   <th>收货人电话：</th><td id="phone"></td>
               </tr>
           </table>
        </div>
        <div class="col-sm-12">
            <table class="table table-striped table-condensed" id="table">
                <tr>
                    <th>书名</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th>小计</th>
                </tr>
                <tr></tr>
            </table>

            <!--<div class="list-group">-->
                <!--<div class="col-sm-12  list-group-item" >-->
                    <!--<div class="col-sm-4 line-center">-->
                        <!--书名-->
                    <!--</div>-->
                    <!--<div class="col-sm-3 line-center">单价</div>-->
                    <!--<div class="col-sm-2 line-center">数量 </div>-->
                    <!--<div class="col-sm-3 line-center">小计</div>-->
                <!--</div>-->
                <!--<div class="col-sm-12  list-group-item" >-->
                    <!--<div class="col-sm-4 line-center">-->
                        <!--书名-->
                    <!--</div>-->
                    <!--<div class="col-sm-3 line-center">单价</div>-->
                    <!--<div class="col-sm-2 line-center">数量 </div>-->
                    <!--<div class="col-sm-3 line-center">小计</div>-->
                <!--</div>-->
                <!--<div class="col-sm-12  list-group-item" >-->
                    <!--<div class="col-sm-4 line-center">-->
                        <!--书名-->
                    <!--</div>-->
                    <!--<div class="col-sm-3 line-center">单价</div>-->
                    <!--<div class="col-sm-2 line-center">数量 </div>-->
                    <!--<div class="col-sm-3 line-center">小计</div>-->
                <!--</div>-->

            <!--</div>-->
        </div>

        <div class="col-sm-12 ">
            <table>
                <tr>
                   <th> </th><th></th> <th>商品总数：</th><td id="orderscount"></td> <th>订单总价：</th><td><span class="text-danger" id="total"></span></label></td>
                </tr>
            </table>
        </div>
    </div>
    <div></div>
    <div class="col-sm-offset-7 col-sm-5" style="padding: 30px;">
        <div class="col-sm-6 btn btn-success btn-block" id="shop">继续购物</div>
        <div class="col-sm-6  btn btn-success btn-block" id="buy">提交订单</div>
        <span id="span"></span>
    </div>
</div>

    <!--footer-->
    <div class="navbar navbar-default navbar-static-bottom ">
        版权声明区
    </div>
<script>
    function getUrlParameter(name){
        name = name.replace(/[]/,"\[").replace(/[]/,"\[").replace(/[]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec(window.parent.location.href );
        if( results == null ) return ""; else {
            return results[1];
        }
    };
    var oid = getUrlParameter('oid');
    window.onload=function () {
        $.ajax({
            url:"/orderitem",
            type:"get",
            data:{
                oid:oid
            },
            success:function (re) {
                console.log(re);
                if (re.code == 1003) {
                    location.href="/Home/Login.html";
                }else if (re.code == 1000) {
                    if (re.username == null) {
                        $("<li><a href=\"Login.html\">登录</a></li>\n" +
                            "                <li><a href=\"Register.html\">注册</a></li>").appendTo("#login")
                    }else {
                        $("<li><a>"+re.username+"</a></li>").appendTo("#login")
                    }
                    $("#oid").html(re.orders.oid);
                    $("#state").html(re.orders.stringstate);
                    $("#username").html(re.orders.username);
                    $("#address").html(re.orders.address);
                    $("#phone").html(re.orders.phone);
                    $("#orderscount").html(re.orders.orderscount);
                    $("#total").html(re.orders.total+"元");
                    for (var i = 0; i < re.orderitem.length; i++) {
                        $("<tr>\n" +
                            "                    <td>"+re.orderitem[i].bname+"</td>\n" +
                            "                    <td>"+re.orderitem[i].price+"</td>\n" +
                            "                    <td>"+re.orderitem[i].count+"</td>\n" +
                            "                    <td>"+re.orderitem[i].subtotal+"</td>\n" +
                            "                </tr>").appendTo("#table");
                    }
                    if (re.orders.state != 1) {
                        $("#buy").remove();
                    }
                }
            }
        })
    };
    $("#buy").click(function () {
        var a=(this)
        $.ajax({
            url:"/buyorders",
            type:"get",
            data:{
                oid:oid,
                newstate:2
            },
            success:function (re) {
                if (re.code == 1003) {
                    location.href="/Home/Login.html";
                }else if (re.code == 1001) {
                    console.log("修改失败")
                    $("#span").html("修改失败")
                }else if (re.code == 1000) {
                    $("#state").html("已付款待发货");
                    a.remove();
                }
            }
        })
    });
    $("#shop").click(function () {
        location.href="/Home/Index.html";
    })
    $("#out").click(function () {
        $.ajax({
            url:"/out",
            type:"get",
            success:function (re) {
                if (re.code == 1000) {
                    location.href="/Home/Login.html"
                }
            }
        })
    })
</script>
</body>
</html>